package com.shouxun.microclassroom;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;

import java.util.ArrayList;

/**
 * Created by zhangshuai on 15/10/12.
 */
public class VoteDetailAdapter extends BaseAdapter {


    private Context mContext;
    private ArrayList<String> mData;
    private ArrayList<String> mData1;
    private ArrayList<String> mData2;
    private int mColors[] = { R.drawable.progress_bg_item1,R.drawable.progress_bg_item2,R.drawable.progress_bg_item3,R.drawable.progress_bg_item4,R.drawable.progress_bg_item5};

    public VoteDetailAdapter(Context mContext,ArrayList<String> mData,ArrayList<String> mData1,ArrayList<String> mData2){
        this.mContext = mContext;
        this.mData = mData;
        this.mData1 = mData1;
        this.mData2 = mData2;
    }


    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null){
            holder = new ViewHolder();
            view = LayoutInflater.from(mContext).inflate(R.layout.vote_item_detail_layout,null);
            holder.title = (TextView) view.findViewById(R.id.vote_detail_item_title);
            holder.mCount = (TextView) view.findViewById(R.id.vote_detail_item_count);
            holder.mProgress = (ProgressBar) view.findViewById(R.id.vote_detail_item_progress);
            view.setTag(holder);

        }else{
            holder = (ViewHolder) view.getTag();
        }
        Drawable progressDrawable = mContext.getResources().getDrawable(mColors[i]);
        holder.mProgress.setProgressDrawable(progressDrawable);
        holder.mProgress.setProgress(Integer.parseInt(mData.get(i)));
        holder.mCount.setText(mData1.get(i));
        holder.title.setText(mData2.get(i));
        return view;
    }

    class ViewHolder{
    	TextView title;
        ProgressBar mProgress;
        TextView mCount;
    }

}
